<?php

function button($texto, $plus = "") {
 conf::$pkj_uid_comp++;
 return "<input type='button' style='padding:5px;width:100%' value='$texto' $plus />";
}

function radio($id, $texto, $grupo = "PADRAO", $plus = "") {
 conf::$pkj_uid_comp++;
 return "<label style='padding:5px;width:100%;cursor:pointer' ><input id='$id' name='$id' type='radio' name='$grupo' value='$texto'  />{$texto}</label>";
//    return "<div style='padding:5px;width:100%;cursor:pointer' onclick='console.log(\"{$id}\", !console.log(\"{$id}\"))' ><input id='rd" . $id . "' type='radio' name='$grupo' value='$texto' onclick='setTimeout(function(){ try{ $clicar }catch(e){} },1)' /><span style='margin-left:10px'>{$texto}</span></div>";
}

function check($id, $texto, $plus = "") {
 conf::$pkj_uid_comp++;
 return "<label style='padding:5px;width:100%;cursor:pointer' ><input id='$id' name='$id' type='checkbox' $plus  style='margin-right:5px'/>{$texto}</label>";
}

function combo($id, $itens, $valoresItens = array(), $plus = "") {
 conf::$pkj_uid_comp++;
 $retorno = "";
 $retorno .= "<select id='$id' name='{$id}' style='padding:5px;width:100%' $plus >";
 $contador = 0;
 foreach ($itens as $value) {
  if (count($valoresItens) > 0):
   $retorno .= "<option value='" . $value . "'>" . $valoresItens[$contador] . "</option>";
  else:
   $retorno .= "<option value='" . $value . "'>" . $value . "</option>";
  endif;

  $contador++;
 }
 $retorno .= "</select><script>$('select').chosen();$( '.chosen-container-single' ).css( 'width' , '100%' )</script>";
 return $retorno;
}

function listSimple($itens, $margem = "5px") {
 conf::$pkj_uid_comp++;
 $retorno = "";
 $retorno .= "<ul>";
 foreach ($itens as $value) {
  $retorno .= "<li >$value</li>";
 }
 $retorno .= "</ul>";
 return $retorno;
}

function listV($itens, $margem = "5px") {
 conf::$pkj_uid_comp++;
 $retorno = "";
 $retorno .= "<ul style='list-style-type: none;'>";
 foreach ($itens as $value) {
  $retorno .= "<li style='margin:" . $margem . "'>$value</li>";
 }
 $retorno .= "</ul>";
 return $retorno;
}

function listH($itens, $margem = "5px") {
 conf::$pkj_uid_comp++;
 $retorno = "";
 $retorno .= "<ul style='list-style-type: none;'>";
 foreach ($itens as $value) {
  $retorno .= "<li style='display:inline;margin:" . $margem . "'>$value</li>";
 }
 $retorno .= "</ul>";
 return $retorno;
}

function label($texto = "", $link = "", $id = "") {
 conf::$pkj_uid_comp++;
 $retorno = "";
 if ($link != "") {
  $retorno = "<a id='$id' href='$link' >$texto</a>";
 } else {
  $retorno = "<span id='$id' style='line-height:30px;height:30px;'>$texto</span>";
 }
 return $retorno;
}

function text($id, $plus = "") {
 conf::$pkj_uid_comp++;
 return "<input id='" . $id . "' name='{$id}' type='text' style='padding:5px;width:100%' $plus />";
}

/**
 * Inicia uma mascara 
 * @param type $id Indetificação do componente
 * @param String $mask Mascara
 * @return String componente
 */
function mask($id, $mask = "999999", $plus = "") {
 conf::$pkj_uid_comp++;
 return "<input id='" . $id . "' name='{$id}' pkjUidComp='pkj" . conf::$pkj_uid_comp . "' type='text' style='padding:5px;width:100%' $plus /><script type='text/javascript'>jQuery(function(){ jQuery('input[pkjUidComp=pkj" . conf::$pkj_uid_comp . "]').mask('" . $mask . "') })</script>";
}

/**
 * Inicia uma data
 * @param type $id Indetificação do componente
 * @return String componente
 */
function date_form($id, $plus = "") {
 conf::$pkj_uid_comp++;  
 return "<input id='" . $id . "' pkjUidComp='pkj" . conf::$pkj_uid_comp . "' name='{$id}' type='text' style='padding:5px;width:100%' $plus />" . "<script type='text/javascript'>jQuery(function(){ jQuery('input[pkjUidComp=pkj" . conf::$pkj_uid_comp . "]').datepicker( { showButtonPanel: true } ).mask('99/99/9999'); })</script>";
}

function number($id, $plus = "") {
 conf::$pkj_uid_comp++;
 return "<input id='" . $id . "' pkjUidComp='pkj" . conf::$pkj_uid_comp . "' name='{$id}' type='text' style='padding:5px;width:100%' $plus />" . "<script type='text/javascript'>jQuery(function(){ jQuery('input[pkjUidComp=pkj" . conf::$pkj_uid_comp . "]').maskMoney({ 'precision':'0' }) })</script>";
}
function money($id, $plus = "") {
 conf::$pkj_uid_comp++;
 return "<input id='" . $id . "' pkjUidComp='pkj" . conf::$pkj_uid_comp . "' name='{$id}' type='text' style='padding:5px;width:100%' $plus />" . "<script type='text/javascript'>jQuery(function(){ jQuery('input[pkjUidComp=pkj" . conf::$pkj_uid_comp . "]').maskMoney({ 'decimal':'.' }) })</script>";
}

function password($id, $plus = "") {
 conf::$pkj_uid_comp++;
 return "<input id='" . $id . "' name='{$id}' type='password' style='padding:5px;width:100%' $plus />";
}

function auto($id, $autocomplete = array('Voce esqueceu de passar o array animal'), $plus = "") {
 conf::$pkj_uid_comp++;
 return "<input id='" . $id . "' name='{$id}' pkjUidComp='pkj" . conf::$pkj_uid_comp . "' type='text' style='padding:5px;width:100%' $plus /><script>jQuery(document).ready(function(){ jQuery('input[pkjUidComp=pkj" . conf::$pkj_uid_comp . "]').autocomplete({source:" . json_encode($autocomplete) . " }); });</script>";
}
function file_form($id,$plus=''){
 conf::$pkj_uid_comp++;
 $r = "<input $plus type=\"file\" style='width:100%' pkjUidComp='pkj".conf::$pkj_uid_comp."' onchange=\"fileData('input[pkjUidComp=pkj".conf::$pkj_uid_comp."]',function(d){ $('#{$id}').val(d); })\"/>";
 $r .= "<input type='hidden' id='{$id}' value='null'/>";
 return $r;
}
function div($elemento = "", $tamanho = "2") {
 conf::$pkj_uid_comp++;
 if ($elemento == "") {
  return "<div class='col_$tamanho' style='height:32px;'>$elemento</div>";
 } else {
  return "<div class='col_$tamanho' style='height:32px;' >$elemento</div>";
 }
}

function td($dados) {
 conf::$pkj_uid_comp++;
 if (is_array($dados)) {
  $retorno = "";
  foreach ($dados as $l) {
   $retorno .= td($l);
  }
  return $retorno;
 } else {
  return "<td>" . $dados . "</td>";
 }
}

function tr($tds) {
 conf::$pkj_uid_comp++;
 return "<tr>" . $tds . "</tr>";
}

function table($trs) {
 conf::$pkj_uid_comp++;
 $html = "";
 if (is_array($trs)) {
  foreach ($trs as $tr) {
   $html .= $tr;
  }
 } else {
  $html = $trs;
 }
 return "<table style='width:100%'>" . $html . "</table>";
}

?>
